/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.losalpes.cliente;

import com.losalpes.datos.RepositorioDatos;
import com.losalpes.persistence.entity.Client;
import com.losalpes.persistence.entity.TipoDocumento;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author Zully
 */
@Stateless
public class ClientServicesMock implements IClientServices {

    RepositorioDatos repositorio;
    
    private Client cClient =  new Client();

    /**
     * Constructor por defecto
     */
    public ClientServicesMock(){
        repositorio = RepositorioDatos.getInstance();
    }

    public void update(Client cClient)
    {
        if(repositorio.getClients().contains(cClient))
        {
            repositorio.getClients().set(repositorio.getClients().indexOf(cClient), cClient);
        }
    }

    public Client getClient()
    {
        return cClient;
    }

    public List<Client> findAll()
    {
        return repositorio.getClients();
    }

    public Client findCliente(String NumeroDocumento) {
        for (Iterator<Client> it = repositorio.getClients().iterator(); it.hasNext();) {
            Client cTemp = it.next();
            if (cTemp.getNumeroDocumento().equals(NumeroDocumento)) {
                return cTemp;
            }
        }
        return null;
    }

    public Client findByEmail(java.lang.String email)
    {
        for (Iterator<Client> it = repositorio.getClients().iterator(); it.hasNext();) {
            Client cTemp = it.next();
            if (cTemp.getEmail().equals(email)) {
                return cTemp;
            }
        }
        return null;       
    }

    public List<com.losalpes.persistence.entity.Client> findByIdentificacion(java.lang.String id)
    {
        ArrayList<Client> temp = new ArrayList<Client>();

        for(Client cTemp : repositorio.getClients())
        {
            if(cTemp.getNumeroDocumento().equalsIgnoreCase(id))
            {
                temp.add(cTemp);
            }
        }
        return temp;
    }

    public void delete(Client cClient)
    {
        if(repositorio.getClients().contains(cClient))
        {
            repositorio.getClients().remove(cClient);
        }
    }

    public void add(Client cClient) {
        repositorio.getClients().add(cClient);
    }
}
